package teste;

import java.sql.SQLException;
import com.wesley.future.Model.Usuario;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;



public class hibernate {  
	  
    
	public static void main(String[] args) {  
  
        try {  
  
            Configuration configuracao = new Configuration()  
                    .configure("/hibernate.cfg.xml");  
            SessionFactory session = configuracao.buildSessionFactory();  
  
            Session sessao = session.openSession();  
              
            //s.connection().setAutoCommit(false);  
              
              
            Usuario novoUsuario = new Usuario();  
            novoUsuario.setNome("administrador");
            novoUsuario.setLogin("adm");
            novoUsuario.setSenha("costa456");
        
            sessao.save(novoUsuario);
            sessao.connection().commit();
            
            System.out.println("Executado");
  
        } catch (HibernateException erroHibernate) {  
            System.out.println("HibernateException = "  
                    + erroHibernate.getMessage());  
  
        } catch (SQLException sqlErro) {  
  
            System.out.println("SQLException = " + sqlErro.getMessage());  
        } 
        
        
    }  
}  


